package com.mfangsoft.zhuangjialong.integration.seller.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mfangsoft.zhuangjialong.app.seller.mapper.SellerEntityMapper;
import com.mfangsoft.zhuangjialong.app.seller.model.SellerEntity;
import com.mfangsoft.zhuangjialong.common.context.UserContext;
import com.mfangsoft.zhuangjialong.common.model.Page;
import com.mfangsoft.zhuangjialong.integration.enums.UserType;
import com.mfangsoft.zhuangjialong.integration.seller.service.SellerService;
import com.mfangsoft.zhuangjialong.integration.user.model.UserEntity;
@Service
public class SellerServiceImpl implements SellerService  {

	
	@Autowired
	private SellerEntityMapper sellerEntityMapper;
	@Override
	public Page<Map<String, Object>> getTuiguangSellerForPage(Page<Map<String, Object>> page) {
		Map<String, Object> map;

		if (page.getParam() != null) {
			map = (Map<String, Object>) page.getParam();
		} else {
			map = new HashMap<>();
			page.setParam(map);
		}

		UserEntity u = UserContext.getCurrentUser();
//		if (u.getUser_type() == UserType.PARTNER.getIndex()) {
//			map.put("partner_id", u.getId() + "");
//
//		}else if (u.getUser_type() == UserType.AGENT.getIndex()) {
//			map.put("agent_id", u.getId());
//		} else if (u.getUser_type() == UserType.SHOP.getIndex()) {
//			map.put("shop_id", u.getId() + "");
//
//		}
		page.setData(sellerEntityMapper.getTuiguangSellerForPage(page));
		return page;
	}
	@Override
	public Page<Map<String, Object>> getSellerForPage(Page<Map<String, Object>> page) {
		// TODO Auto-generated method stub
		Map<String, Object> map;

		if (page.getParam() != null) {
			map = (Map<String, Object>) page.getParam();
		} else {
			map = new HashMap<>();
			page.setParam(map);
		}

		UserEntity u = UserContext.getCurrentUser();
//		if (u.getUser_type() == UserType.PARTNER.getIndex()) {
//			map.put("partner_id", u.getId() + "");
//		}else if (u.getUser_type() == UserType.AGENT.getIndex()) {
//			map.put("agent_id", u.getId());
//		} else if (u.getUser_type() == UserType.SHOP.getIndex()) {
//			map.put("shop_id", u.getId() + "");
//		}
		
		page.setData(sellerEntityMapper.getSeller23ForPage(page));

		return page;
	}
	public Map<String, Object> getOneSeller(SellerEntity sellerEntity) {

		return sellerEntityMapper.selectByPrimaryKeyForBack(sellerEntity.getId());
	}
	

}
